using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;

namespace Sec_scan漏洞扫描系统.Sec_Service
{
    /// <summary>
    /// 通用请求方法
    /// </summary>
    public class Sec_Request_Service
    {
        /// <summary>
        /// 采用get的方式进行请求
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string RequestGet(string req)
        {
            string url = Sec_Api.Sec_Request_Service_Api.Url;
            //Sec_Api.Sec_Request_Service_Api.StatusExps = new StringBuilder();
            //Sec_Api.Sec_Request_Service_Api.StatusOk = new StringBuilder();
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                var stat = response;
                if(stat.StatusCode == HttpStatusCode.OK)
                {
                    string statok = "访问成功！";
                    Sec_Api.Sec_Request_Service_Api.StatusOk = statok;
                    Sec_Config.Sec_CacheInfo.CacheInsert("okinfo", statok);
                }
            }
            catch(Exception ex)
            {
                string Exp = ex.ToString();
                string Exps = "网站无法访问！";
                Sec_Api.Sec_Request_Service_Api.StatusExp = Exp;
                Sec_Api.Sec_Request_Service_Api.StatusExps = Exps;
                Sec_Config.Sec_CacheInfo.CacheInsert("okno",Exps);
            }
            return req;
        }
        /// <summary>
        /// POST请求方法
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string RequestPost(string req)
        {
            string url = Sec_Api.Sec_Request_Service_Api.Url;
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "POST";
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    string statok = "访问成功！";
                    Sec_Api.Sec_Request_Service_Api.StatusOk = statok;
                }
            }
            catch (Exception ex)
            {
                string Exp = ex.ToString();
                string Exps = "网站无法访问！";
                Sec_Api.Sec_Request_Service_Api.StatusExp = Exp;
                Sec_Api.Sec_Request_Service_Api.StatusExps = Exps;
            }
            return req;
        }
    }
}
